package com.linked.basemanage.config;

import com.linked.basemanage.pass.service.IPassHandleService;
import com.linked.basemanage.util.HandleRedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author :dbq
 * @date : 2023/3/27 8:43
 * @description : redis预加载
 */
@Slf4j
@Component
public class PreloadConfig implements ApplicationRunner {


    private final HandleRedisUtils redisUtils;

    private final IPassHandleService passHandleService;


    public PreloadConfig(HandleRedisUtils redisUtils, IPassHandleService passHandleService) {
        this.redisUtils = redisUtils;
        this.passHandleService = passHandleService;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            redisUtils.getRedisValueList(RedisKeysConfig.KEY_BLACKLIST, () -> passHandleService.queryBlackList());
        } catch (Exception e) {
            log.error("redis预加载黑名单数据 异常！", e);
        }

        try {
            redisUtils.getRedisValueList(RedisKeysConfig.KEY_WIHTELIST, passHandleService::queryWihteList);
        } catch (Exception e) {
            log.error("redis预加载白名单数据 异常！", e);
        }
    }
}
